/*
 * The RavenX Library
 * Copyright (c) 2008 by Solidus
 * 
 * Permission to use, copy, modify, distribute and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.It is provided "as is" without express 
 * or implied warranty.
 *
 */

#ifndef RX_FUNC_H
#define RX_FUNC_H

#include "rx_typedef.h"


RX_SPACE_BEG



typedef struct __rx_wstr_tag rx_wstr_t;

RavenAPI void			rx_wstr_trimleft(rx_wstr_t *self, const rx_wchar *target);
RavenAPI void			rx_wstr_trimright(rx_wstr_t *self, const rx_wchar *target);
RavenAPI void			rx_wstr_trim(rx_wstr_t *self, const rx_wchar *target);


RavenAPI rx_wstr_t*		rx_wstr_create();

RavenAPI void			rx_wstr_destroy(rx_wstr_t *self);

RavenAPI rx_wstr_t *	rx_wstr_dup(const rx_wstr_t *self);

RavenAPI void			rx_wstr_copy(rx_wstr_t *dest, const rx_wstr_t *self);

RavenAPI void			rx_wstr_clear(rx_wstr_t *self);

RavenAPI size_t			rx_wstr_size(const rx_wstr_t *self);

RavenAPI size_t			rx_wstr_capacity(const rx_wstr_t *self);

RavenAPI void			rx_wstr_reserve(rx_wstr_t *self, size_t num_wchars);

RavenAPI void			rx_wstr_append(rx_wstr_t *self, const rx_wchar *str);

RavenAPI void			rx_wstr_erase_pos(rx_wstr_t *self, size_t pos);

RavenAPI void			rx_wstr_erase_range(rx_wstr_t *self, size_t first, size_t last);

RavenAPI void			rx_wstr_erase_value(rx_wstr_t *self, size_t start_pos, rx_wchar value);

RavenAPI void			rx_wstr_insert_value(rx_wstr_t *self, size_t pos, rx_wchar value, size_t n);

RavenAPI void			rx_wstr_insert(rx_wstr_t *self, size_t pos, const rx_wchar *str);

RavenAPI rx_bool		rx_wstr_format(rx_wstr_t *self, const rx_wchar *fmt,...);

RavenAPI rx_bool		rx_wstr_append_format(rx_wstr_t *self, const rx_wchar *fmt,...);

RavenAPI rx_wstr_t*		rx_wstr_substr(const rx_wstr_t *self, size_t first, size_t last);

RavenAPI rx_wchar*		rx_wstr_begin(rx_wstr_t *self);

RavenAPI rx_wchar*		rx_wstr_end(rx_wstr_t *self);

RavenAPI rx_wchar*		rx_wstr_at(rx_wstr_t *self, size_t idx);

RavenAPI const rx_wchar* rx_wstr_cstr(const rx_wstr_t *self);

RavenAPI int	rx_wstr_search_pos(const rx_wstr_t *self, size_t pos, const rx_wchar *key);

RavenAPI int	rx_wstr_search(const rx_wstr_t *self, const rx_wchar *key);

RavenAPI int	rx_wstr_cmp(const rx_wstr_t *left, const rx_wstr_t *right);


RavenAPI rx_uint_n rx_wstr_hash(const rx_wstr_t *self);


/*************************************mbcs****************************************/

typedef struct __rx_str_tag rx_str_t;

RavenAPI void	rx_str_trim(rx_str_t *self, const rx_char *target);
RavenAPI void	rx_str_trimright(rx_str_t *self, const rx_char *target);
RavenAPI void	rx_str_trimleft(rx_str_t *self, const rx_char *target);


RavenAPI rx_str_t*	rx_str_dup(const rx_str_t *self);

RavenAPI void	rx_str_copy(rx_str_t *dest, const rx_str_t *self);

RavenAPI rx_str_t*		rx_str_create();

RavenAPI void			rx_str_destroy(rx_str_t *self);

RavenAPI void			rx_str_clear(rx_str_t *self);

RavenAPI size_t			rx_str_size(const rx_str_t *self);

RavenAPI size_t			rx_str_capacity(const rx_str_t *self);

RavenAPI void			rx_str_reserve(rx_str_t *self, size_t num_wchars);

RavenAPI void			rx_str_append(rx_str_t *self, const rx_char *str);

RavenAPI void			rx_str_erase_pos(rx_str_t *self, size_t pos);

RavenAPI void			rx_str_erase_range(rx_str_t *self, size_t first, size_t last);

RavenAPI void			rx_str_erase_value(rx_str_t *self, size_t start_pos, rx_char value);

RavenAPI void			rx_str_insert_value(rx_str_t *self, size_t pos, rx_char value, size_t n);

RavenAPI void			rx_str_insert(rx_str_t *self, size_t pos, const rx_char *str);

RavenAPI rx_bool		rx_str_format(rx_str_t *self, const rx_char *fmt,...);

RavenAPI rx_str_t*		rx_str_substr(const rx_str_t *self, size_t first, size_t last);

RavenAPI rx_char*		rx_str_begin(rx_str_t *self);

RavenAPI rx_char*		rx_str_end(rx_str_t *self);

RavenAPI rx_char*		rx_str_at(rx_str_t *self, size_t idx);

RavenAPI const rx_char* rx_str_cstr(const rx_str_t *self);

RavenAPI int	rx_str_search_pos(const rx_str_t *self, size_t pos, const rx_char *key);

RavenAPI int	rx_str_search(const rx_str_t *self, const rx_char *key);

RavenAPI int	rx_str_cmp(const rx_str_t *left, const rx_str_t *right);

RavenAPI rx_uint_n rx_str_hash(const rx_str_t *self);



/************************************uni_str*****************************************/

typedef struct __rx_unistr_tag rx_unistr_t;

RavenAPI rx_unistr_t* rx_unistr_dup(const rx_unistr_t *self);

RavenAPI rx_unistr_t* rx_unistr_create();

RavenAPI void rx_unistr_destroy(rx_unistr_t *pstr);

RavenAPI rx_unistr_t* rx_unistr_create_wstr(const rx_wchar *str);

RavenAPI rx_unistr_t* rx_unistr_create_str(const rx_char *str);

RavenAPI rx_wstr_t*	rx_unistr_to_wstr(rx_unistr_t *pstr);

RavenAPI rx_str_t*	rx_unistr_to_str(rx_unistr_t *pstr);

RavenAPI rx_unistr_t* rx_wstr_to_unistr(rx_wstr_t *pstr);

RavenAPI rx_unistr_t* rx_str_to_unistr(rx_str_t	*str);

RavenAPI rx_str_t*	rx_unistr_to_utf8(rx_unistr_t *pstr);

RavenAPI void rx_unistr_copy(rx_unistr_t *dest, const rx_unistr_t *self);

RavenAPI const rx_char* rx_unistr_cstr(const rx_unistr_t *self); 

RavenAPI const rx_wchar* rx_unistr_wcstr(const rx_unistr_t *self);




#define RX_UNISTR	rx_unistr_create()

#define RX_UNI_STR(str) (rx_unistr_create_str(str))

#define RX_UNI_WSTR(str) (rx_unistr_create_wstr(str))

#define RX_TO_STR(str) rx_unistr_to_str(str)

#define RX_TO_WSTR(str) rx_unistr_to_wstr(str)

#define RX_WSTR(str) rx_unistr_wcstr(str)

#define RX_STR(str)	rx_unistr_cstr(str)


#define rx_wstr_append_wstr(self, wstr) rx_wstr_append(self, rx_wstr_cstr(wstr))
#define rx_str_append_str(self, str) rx_str_append(self, rx_str_cstr(str))


/********************************tokenizer********************************************/


typedef struct __rx_strtok_ctx_tag rx_strtok_ctx;

RavenAPI rx_strtok_ctx*			rx_strtok_init(const rx_char *str, rx_bool trim);

RavenAPI void					rx_strtok_destroy(rx_strtok_ctx *ctx);

RavenAPI void					rx_strtok_reset(rx_strtok_ctx *ctx);

RavenAPI const rx_char*			rx_strtok(rx_strtok_ctx *ctx, rx_bool (*is_delim_f)(rx_char, const void *), const void *sep);

RavenAPI const rx_char*			rx_strtok_str(rx_strtok_ctx *ctx, const rx_char *sep);






typedef struct __rx_wcstok_ctx_tag		rx_wcstok_ctx;

RavenAPI rx_wcstok_ctx*			rx_wcstok_init(const rx_wchar *str,  rx_bool trim);

RavenAPI const rx_wchar*		rx_wcstok_str(rx_wcstok_ctx *ctx, const rx_wchar *sep);

RavenAPI const rx_wchar* rx_wcstok(rx_wcstok_ctx *ctx, rx_bool (*is_delim_f)(rx_wchar, const void*), const void *sep);
RavenAPI void					rx_wcstok_destroy(rx_wcstok_ctx *ctx);

RavenAPI void					rx_wcstok_reset(rx_wcstok_ctx *ctx);









RX_SPACE_END


#endif




